class Solution(object):
    def rangeSum(self, nums, n, left, right):
        for i in range(1, n):
            nums[i] += nums[i - 1]
        ans = []
        for i in range(n):
            for j in range(i, n):
                if i == 0:
                    ans.append(nums[j])
                else:
                    ans.append(nums[j] - nums[i - 1])
        ans.sort()
        return sum(ans[left - 1: right]) % (10 ** 9 + 7)
